/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package net.ytbolg.mcxa;

import net.ytbolg.mcxa.util.DownLoadURL;
import net.ytbolg.mcxa.LangAndConfig.LangFile;
import net.ytbolg.mcxa.LangAndConfig.Config;
import net.ytbolg.mcxa.LangAndConfig.Lang;
import net.ytbolg.mcxa.util.VersionCheck;
import net.ytbolg.mcxa.util.Updater;
import net.ytbolg.mcxa.util.ForgeCheck;
import java.awt.HeadlessException;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
//import java.lang.System;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.zip.ZipFile;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.xml.parsers.ParserConfigurationException;
//iLauncher.mport javax.xml.parsers.ParserConfigurationException;
//import static net.ytbolg.mcxa.GameInfo.tpf;
import net.ytbolg.mcxa.Launcher.GameInfo;
import static net.ytbolg.mcxa.Launcher.GameInfo.tpf;
import net.ytbolg.mcxa.Launcher.GameInfoGet;
import net.ytbolg.mcxa.Launcher.MakeCmd;
import net.ytbolg.mcxa.Launcher.YggdrasilCheck;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 *
 * @author Ytong
 */
public class MCLaucherXA extends javax.swing.JFrame {

    static net.ytbolg.mcxa.Output.Logger l = new net.ytbolg.mcxa.Output.Logger(0);
    public static AssetsDownloader ad = new AssetsDownloader();
    public static final String MainTitle = "MCLauncherXA xxx by officeyutong".replaceAll("xxx", LangFile.Version);
    static ConfigFrame c = new ConfigFrame();
//    static Properties p = new Properties();
    JSONObject vs[];

    /**
     * Creates new form MCLaucherXA
     */
    public MCLaucherXA() {
        initComponents();
        // l=;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPopupMenu1 = new javax.swing.JPopupMenu();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        lxbq = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        fbbq = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jCheckBox1 = new javax.swing.JCheckBox();
        jPasswordField1 = new javax.swing.JPasswordField();
        jLabel8 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem5 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jList1.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jList1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jList1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jList1);

        jPanel1.setToolTipText("");

        jLabel1.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jLabel1.setText("版本类型");

        lxbq.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        lxbq.setText("jLabel2");

        jLabel3.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jLabel3.setText("发布时间");

        fbbq.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        fbbq.setText("jLabel4");

        jLabel6.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jLabel6.setText("注：本启动器使用了BMCLVAPI!");

        jLabel9.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jLabel9.setText("启动参数");

        jComboBox1.setEditable(true);
        jComboBox1.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-Dfml.ignoreInvalidMinecraftCertificates=true -Dfml.ignorePatchDiscrepancies=true" }));
        jComboBox1.setSelectedIndex(-1);

        jButton1.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jButton1.setText("启动");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lxbq))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(fbbq)))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(33, 33, 33))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(lxbq))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(fbbq))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel6))
        );

        jLabel2.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N

        jTextField1.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jTextField1.setText("        ");

        jLabel4.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jLabel4.setText("启动内存");

        jTextField2.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jTextField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField2ActionPerformed(evt);
            }
        });
        jTextField2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextField2KeyTyped(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jLabel5.setText("MB");

        jCheckBox1.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        jPasswordField1.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jPasswordField1.setEchoChar('*');

        jLabel7.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jLabel7.setForeground(new java.awt.Color(255, 51, 51));
        jLabel7.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel7MouseClicked(evt);
            }
        });

        jMenuBar1.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N

        jMenu1.setText("文件");
        jMenu1.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N

        jMenuItem1.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jMenuItem1.setText("下载版本");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuItem3.setText("下载Forge");
        jMenuItem3.setToolTipText("");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuItem2.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jMenuItem2.setText("设置");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuItem4.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jMenuItem4.setText("检查更新");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem4);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("帮助");
        jMenu2.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N

        jMenuItem5.setText("关于");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem5);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jCheckBox1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(55, 55, 55)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jPasswordField1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jLabel5)))))
                        .addGap(0, 10, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addGap(5, 5, 5)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 274, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(20, 20, 20)
                                .addComponent(jCheckBox1)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel4))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel5))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated

    }//GEN-LAST:event_formWindowActivated

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        l.Log("Launching...");
        GameInfo.lauchArg = jComboBox1.getSelectedItem().toString();
        // jButton2.setVisible(false);
        File f = new File(GameInfo.GameDir + tpf + "launcher_profiles.json");
        if (!f.exists()) {
            l.Log("launcher_profiles.json Not found,will create");
            try {
                FileWriter w = new FileWriter(f);
                w.write("{\n"
                        + "	\"selectedProfile\": \"(Default)\",\n"
                        + "	\"profiles\": {\n"
                        + "		\"Forge\": {\n"
                        + "			\"name\": \"Forge\",\n"
                        + "			\"lastVersionId\": \"1.7.10-Forge10.13.1.1217\"\n"
                        + "		}\n"
                        + "	},\n"
                        + "	\"clientToken\": \"adfgaasd\"\n"
                        + "}");
                w.close();
            } catch (IOException ex) {
                Logger.getLogger(MCLaucherXA.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        if (jList1.getSelectedIndex() == -1) {
            JOptionPane.showMessageDialog(null, Lang.getLang("Main_NoselectVersion"), Lang.getLang("Main_NoselectVersionTitle"), JOptionPane.WARNING_MESSAGE);
            return;
        }

        //    System.out.println("a");
        if (jTextField1.getText().equals("")) {
            JOptionPane.showMessageDialog(null, Lang.getLang("Main_NoUserName"), Lang.getLang("Main_Error"), JOptionPane.WARNING_MESSAGE);
            return;
        }
        if (jTextField2.getText().equals("")) {
            JOptionPane.showMessageDialog(null, Lang.getLang("Main_NoMemory"), Lang.getLang("Main_Error"), JOptionPane.WARNING_MESSAGE);
            return;
        }
        GameInfo.memory = jTextField2.getText();
        Config.setConfig("username", jTextField1.getText());
        Config.setConfig("lastgameversion", String.valueOf(jList1.getSelectedIndex()));
        Config.setConfig("lastmemory", jTextField2.getText());
        Config.setConfig("iszhengban", String.valueOf(jCheckBox1.isSelected()));
        Config.setConfig("zhengbanmima", String.valueOf(jPasswordField1.getPassword()));
////    //    System.out.println(GameInfo.Rundir + tpf + "MCXA.cfg");
        Config.Save();
        YggdrasilCheck y = YggdrasilCheck.getThis();
        String name = jTextField1.getText();
        try {
            if (jCheckBox1.isSelected()) {
                l.Log("Logining..");
                JSONObject j = new JSONObject(y.login(y.GenLoginJson(jTextField1.getText(), String.valueOf(jPasswordField1.getPassword()))));
                if (j.has("errorMessage")) {
                    JOptionPane.showMessageDialog(null, Lang.getLang("Main_LoginFaild") + "\n" + j.getString("errorMessage"), Lang.getLang("Main_Error"), JOptionPane.WARNING_MESSAGE);
                }
                l.Log("returned json:" + j);
                name = new JSONObject(j.getString("selectedProfile")).getString("name");
                //  GameInfo.uuid=j.get("clientToken");
                GameInfo.token = j.getString("accessToken");
                //  System.out.println(j);

                GameInfo.uuid = j.getJSONObject("selectedProfile").getString("id");
                if (j.has("user")) {
                    JSONObject j2 = j.getJSONObject("user");
                    if (j2.has("properties")) {

                        JSONArray ja = j2.getJSONArray("properties");
                        l.Log("properties:" + ja);//     System.out.println(ja);
                        for (int y1 = 0; y1 < ja.length(); y1++) {
                            JSONObject jo3 = ja.getJSONObject(y1);
                            if (jo3.getString("name").equals("twitch_access_token")) {
                                //       System.out.println(jo3);
                                GameInfo.twitchToken = "{\"twitch_access_token\":\"[" + jo3.getString("value") + "\"]}";
                            }
                        }
                    }
                }

            }

        } catch (IOException ex) {
            JOptionPane.showMessageDialog(null, Lang.getLang("Main_LoginFaild") + "\n" + ex, Lang.getLang("Main_Error"), JOptionPane.WARNING_MESSAGE);
            new net.ytbolg.mcxa.Output.Logger(1).Log("Login faild"+ex);
            return;
//  Logger.getLogger(MCLaucherXA.class.getName()).log(Level.SEVERE, null, ex);
        } catch (JSONException ex) {
              new net.ytbolg.mcxa.Output.Logger(1).Log("Login faild"+ex);
            JOptionPane.showMessageDialog(null, Lang.getLang("Main_LoginFaild"), Lang.getLang("Main_Error"), JOptionPane.WARNING_MESSAGE);
            return;
        }
        if (GameInfo.twitchToken.equals("")) {
            GameInfo.twitchToken = "{}";
        }
//GameInfo.token="auth_access_token";
        GameInfo.UserName = name;
        LauchInfoWindow.version = jList1.getSelectedValue().toString();
        l.Log("Logining successfully");
        new LauchInfoWindow().setVisible(true);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jList1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jList1MouseClicked
        if (jList1.getSelectedIndex() == -1) {
            return;
        }

        try {
            if (MakeCmd.isChanged(new ZipFile(GameInfo.GameDir + tpf + "versions" + tpf + jList1.getSelectedValue().toString() + tpf + jList1.getSelectedValue().toString() + ".jar"))) {
                jComboBox1.setSelectedItem("-Dfml.ignoreInvalidMinecraftCertificates=true -Dfml.ignorePatchDiscrepancies=true");
            } else {
                jComboBox1.setSelectedItem(" ");
            }
        } catch (IOException ex) {
            Logger.getLogger(MCLaucherXA.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (evt == null) {
            return;
        }
        if (evt.getButton() == MouseEvent.BUTTON3 && jList1.getSelectedIndex() != -1) {
            jPopupMenu1.show(this, evt.getX() + 25, evt.getY() + 25);
        }
        if (evt.getButton() == MouseEvent.BUTTON2 && evt.getClickCount() == 2) {
            jButton1ActionPerformed(null);
        }
        try {
            BrushLabels(jList1.getSelectedIndex());
        } catch (JSONException e) {
            e.printStackTrace();;
        } catch (Exception ex) {
            Logger.getLogger(MCLaucherXA.class.getName()).log(Level.SEVERE, null, ex);
        }
        // TODO add your handling code here:
    }//GEN-LAST:event_jList1MouseClicked

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed

        new VersionCheck().setVisible(true);
        jList1.setListData(GameInfoGet.getGameVersions());// TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jTextField2KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField2KeyTyped
//if(evt.getKeyChar())
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField2KeyTyped

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        Config.setConfig("username", jTextField1.getText());
        Config.setConfig("lastgameversion", String.valueOf(jList1.getSelectedIndex()));
        Config.setConfig("lastmemory", jTextField2.getText());

        Config.Save();
   //     ConfigClass.showlauchinfowindows = Boolean.valueOf(p.getProperty("showlauchinfowindows"));


            new ConfigFrame().setVisible(true);    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField2ActionPerformed

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
        jPasswordField1.setEnabled(jCheckBox1.isSelected());        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBox1ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        new ForgeCheck().setVisible(true);
        jList1.setListData(GameInfoGet.getGameVersions());// TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem3ActionPerformed
    public static boolean deleteDir(File dir) {
        if (dir.isDirectory()) {
            String[] children = dir.list();

            for (String children1 : children) {
                boolean success = deleteDir(new File(dir, children1));
                if (!success) {
                    return false;
                }
            }
        }
        // 目录此时为空，可以删除
        return dir.delete();
    }
    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        //    GameInfo.uuid = UUID.randomUUID().toString().toUpperCase().replace("-", "");
        //     GameInfo.rb.getBundle(tpf)
        l.Log("Showing window");
//        jMenu3.setVisible(false);
        setTitle(MainTitle);
        jLabel2.setText(Lang.getLang("Main_Label_Username"));
        jCheckBox1.setText(Lang.getLang("Main_CheckBox_zhangben"));
        jLabel4.setText(Lang.getLang("Main_Label_Memory"));
        jLabel1.setText(Lang.getLang("Main_Label_Type"));
        jLabel3.setText(Lang.getLang("Main_Label_Time"));
        jLabel6.setText(Lang.getLang("Main_Label_BMCLVAPI"));
        jButton1.setText(Lang.getLang("Main_Button_Lauch"));
        //  jButton2.setText(Lang.getLang("Main_Button_GetAss"));
        jMenu1.setText(Lang.getLang("Main_Menu_File"));
        jMenu2.setText(Lang.getLang("Main_Menu_Help"));
        jMenuItem1.setText(Lang.getLang("Main_Menu_DownVersion"));
        jMenuItem3.setText(Lang.getLang("Main_Menu_DownForge"));
        jMenuItem2.setText(Lang.getLang("Main_Menu_Config"));
        jMenuItem4.setText(Lang.getLang("Main_Menu_Update"));
        //  jMenuItem4.setText(Lang.getLang("Main_Menu_Delete"));
        jLabel7.setText(Lang.getLang("Main_Label_Update"));
        jLabel9.setText(Lang.getLang("Main_Label_AppArgs"));
        jLabel7.setVisible(false);
        JMenuItem ji = jPopupMenu1.add(Lang.getLang("Main_Menu_Delete"));
        JMenuItem j2 = jPopupMenu1.add(Lang.getLang("Main_Menu_Brush"));
        JMenuItem j3 = jPopupMenu1.add(Lang.getLang("Main_Button_GetAss"));
        JMenuItem j4 = jPopupMenu1.add(Lang.getLang("Main_Menu_RedownloadLib"));

        j2.addMouseListener(new MouseListener() {

            @Override
            public void mouseClicked(MouseEvent e) {

                //  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void mousePressed(MouseEvent e) {
                jList1.setListData(GameInfoGet.getGameVersions());
                //   throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                //  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                //     throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void mouseExited(MouseEvent e) {
                //   throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
        });
        ji.addMouseListener(new MouseListener() {

            @Override
            public void mouseClicked(MouseEvent e) {

//if(e.getComponent().)            
//    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void mousePressed(MouseEvent e) {
                //     System.out.println("Right click");
                if (e.getButton() == MouseEvent.BUTTON1) {
                    l.Log("Deleting:" + GameInfo.GameDir + tpf + "versions" + tpf + jList1.getSelectedValue().toString());

                    deleteDir(new File(GameInfo.GameDir + tpf + "versions" + tpf + jList1.getSelectedValue().toString()));
                    jList1.setListData(GameInfoGet.getGameVersions());
                }   //      System.out.println("Right click"); // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void mouseExited(MouseEvent e) {
                //  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            public void mouseDragged(MouseEvent e) {

            }
        });
        j3.addMouseListener(new MouseListener() {

            @Override
            public void mouseClicked(MouseEvent e) {

                //   throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void mousePressed(MouseEvent e) {
                GameInfo.assVersion = jList1.getSelectedValue().toString();
                try {
                    GetAss();
                    //  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                } catch (ParserConfigurationException ex) {
                    Logger.getLogger(MCLaucherXA.class.getName()).log(Level.SEVERE, null, ex);
                }
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                //   throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                /////   throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void mouseExited(MouseEvent e) {
                //  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
        });
        j4.addMouseListener(new MouseListener() {

            @Override
            public void mouseClicked(MouseEvent e) {
                //    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void mousePressed(MouseEvent e) {
                try {
                    Downloader d = new Downloader();
                    d.setUnzip(false);
                    String al = GameInfoGet.libstotruedir(GameInfoGet.getLibs(jList1.getSelectedValue().toString()));
                    String libs[] = al.split(";");
                    for (int a = 0; a < libs.length; a++) {
                        libs[a] = libs[a].substring(1, libs[a].length() - 1);
                    }
                    for (String lib : libs) {
                        File f = new File(lib);
                        if (f.exists()) {
                            f.delete();
                        }
                        d.add(DownLoadURL.getURL(DownLoadURL.LIBRARIES, Integer.valueOf(Config.getConfig("DownSou"))) + lib.replaceFirst(Matcher.quoteReplacement(GameInfo.GameDir + tpf + "libraries"), ""), lib);
                    }
                    d.setVisible(true);
                    d.start();

                    //   throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                } catch (IOException | JSONException ex) {
                    Logger.getLogger(MCLaucherXA.class.getName()).log(Level.SEVERE, null, ex);
                }
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                //  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                //      throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void mouseExited(MouseEvent e) {
                //   throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
        });

//  this.setIconImage(this.getToolkit().getImage(getClass().getResource("/icon_16x16.icon")));
        //   System.out.println(p.getProperty("zhengbanmima"));
        jCheckBox1.setSelected(Config.getConfig("iszhengban").equals("true"));
        jCheckBox1ActionPerformed(null);
        setLocationRelativeTo(getOwner());
        if (!System.getProperty("os.name").contains("Windows")) {
            //  jLabel8.setText(Lang.getLang("Main_NotWindows"));
            //   jLabel9.setText();

        }

        this.setResizable(false);
        jList1.setListData(GameInfoGet.getGameVersions());// TODO add your handling code here:
        GameInfo.downUrl = Config.getConfig("downUrl");
        try {
            int m = GameInfoGet.getGameVersions().length;
            vs = new JSONObject[m];
            //  System.out.println(m);
            for (int i = 0; i < m; i++) {
                vs[i] = new JSONObject(ReadFile(GameInfo.GameDir + tpf + "versions" + tpf + GameInfoGet.getGameVersions()[i] + tpf + GameInfoGet.getGameVersions()[i] + ".json"));
            }
            jPasswordField1.setText(Config.getConfig("zhengbanmima"));
            if (Config.getConfig("zhengbanmima").equals("")) {
                jCheckBox1.setSelected(false);
                jPasswordField1.setEnabled(false);

            }
            jTextField1.setText(Config.getConfig("username"));
            jTextField2.setText(Config.getConfig("lastmemory"));
            int i = 0;
            //     System.out.println(p.getProperty("lastgameversion"));
            i = Integer.parseInt(Config.getConfig("lastgameversion"));
            if (i < 0) {
                i = 0;
            }
            jList1.setSelectedIndex(i);
            if (jList1.getModel().getSize() != 0) {
                BrushLabels(jList1.getSelectedIndex());
            }
            //    OutputStream in = new FileOutputStream(GameInfo.Rundir + tpf + "MCXA.cfg");
            Config.Save();
// p.store(in, "= =");
            jList1MouseClicked(null);

            new Thread(new checkUpdate(jLabel7)).start();
        } catch (IOException | JSONException | NumberFormatException ex) {
            Logger.getLogger(MCLaucherXA.class.getName()).log(Level.SEVERE, null, ex);
        }
        // TODO add your handling code here:
    }//GEN-LAST:event_formWindowOpened

    private void jLabel7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel7MouseClicked
        new Updater().setVisible(true);        // TODO add your handling code here:
    }//GEN-LAST:event_jLabel7MouseClicked

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
        new Updater().setVisible(true);      // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem4ActionPerformed

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
        new About().setVisible(true);        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem5ActionPerformed

    /**
     * @param args the command line arguments
     * @throws java.lang.Exception
     */
    public static void main(String args[]) throws InterruptedException, IOException {
        l.Log("MCLauncherXA " + LangFile.Version + " Launching");

        try {
            String tx = new File(".").getCanonicalPath();
            if (tx.endsWith("\\")) {
                tx = tx.substring(0, tx.length() - 1);
            }
            File f2 = new File(tx + "/update.note");
            l.Log("Update.note.exists()=" + (f2.exists() ? "true" : "false"));
            l.Log("Update.note.toString()=" + f2.toString());
            if (f2.exists()) {
                //        Thread.sleep(3000);
                String x = ReadFile(f2.toString());
                l.Log("Update.note.read()=" + x);
                f2.deleteOnExit();
                new File(x).delete();

            }
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            //      Test t = new Test("H:\\mclaucherxa\\");
            //  t.countJavaFile(t.projectPath);
            GameInfo.tpf = getTpf();
            //    GameInfo.JavaPath = "java";
            String fgf = System.getProperty("os.name").contains("Linux") ? "'" : "\"";
            if (!System.getProperty("os.name").contains("Windows")) {
                //       GameInfo.JavaPath = "java";
                GameInfo.JavaPath = System.getProperty("java.home") + tpf + "bin" + tpf + "java";
            } else {
                //  GameInfo.JavaPath = "java";
                GameInfo.JavaPath = System.getProperty("java.home") + tpf + "bin" + tpf + "java.exe";
            }
            //  GameInfo.GameDir = "J:\\NewZM\\client\\.minecraft";
            //   GameInfoGet.getGameVersions();
            GameInfo.Rundir = new File(".").getCanonicalPath();
            l.Log("Game Dir=" + GameInfo.Rundir);
            if (GameInfo.Rundir.endsWith("\\")) {
                GameInfo.Rundir = GameInfo.Rundir.substring(0, GameInfo.Rundir.length() - 1);
            }
            //    System.out.println(GameInfo.Rundir);
            GameInfo.GameDir = GameInfo.Rundir + GameInfo.tpf + ".minecraft";

            //下面是创建配置
            String Files[] = {"sChinese.lang", "tChinese.lang", "English.lang"};
            String Langs[] = {LangFile.sChinese, LangFile.tChinese, LangFile.english};
            ArrayList<File> file = new ArrayList<>();

            for (int i = 0; i < Files.length; i++) {
                File f = new File(GameInfo.Rundir + tpf + "MCXA.Lang" + tpf + Files[i]);
                File par = f.getParentFile();
                if (par.isFile() || !par.exists()) {
                    par.mkdir();
                }
                l.Log("Language Path:" + f);
                if (!f.exists()) {
                    f.createNewFile();
                    file.add(f);
                }
            }
            for (int i = 0; i < file.size(); i++) {

                FileWriter fw = new FileWriter(file.get(i));
                fw.write(Langs[i]);
                fw.close();
            }
            // getClass().getResource("/sChinese.lang").

            if (!(new File(GameInfo.Rundir + tpf + "MCXA.json")).exists()) {
                l.Log("Config file not found");
                new File(GameInfo.Rundir + tpf + "MCXA.json").createNewFile();
                FileWriter fw = new FileWriter(GameInfo.Rundir + tpf + "MCXA.json");
                fw.write("{}");
                fw.close();
                //   p.load(new FileInputStream(GameInfo.Rundir + tpf + "MCXA.cfg"));
                String playerxxx = String.valueOf(new Random().nextInt(999));
                if (playerxxx.length() != 3) {
                    for (int i = 1; i < playerxxx.length() - 1; i++) {
                        playerxxx = "0" + playerxxx;
                    }
                }
                l.Log("Creating config...");
                Config.Load(new File(GameInfo.Rundir + tpf + "MCXA.json"));
                Config.setConfig("username", "player" + playerxxx);
                Config.setConfig("lastgameversion", "0");
                Config.setConfig("lastmemory", "1500");
                //   Config.setConfig("showlauchinfowindows", "true");
                Config.setConfig("showlauchinfo", "true");
                Config.setConfig("ifclose", "true");
                Config.setConfig("zhengbanmima", "");
                Config.setConfig("DownSou", "1");
                Config.setConfig("Lang", "sChinese.lang");
                Config.setConfig("iszhengban", "false");
                Config.setConfig("GameDir", GameInfo.GameDir);
                Config.setConfig("JavaPath", GameInfo.JavaPath);
                Config.setConfig("isDuli", "false");
                Config.Save();

            } else {
                Config.Load(new File(GameInfo.Rundir + tpf + "MCXA.json"));
            }
            GameInfo.GameDir = Config.getConfig("GameDir");
            if (new File(GameInfo.GameDir).exists() == false) {
                Config.setConfig("GameDir", GameInfo.Rundir + tpf + ".minecraft");
                GameInfo.GameDir = Config.getConfig("GameDir");
                Config.Save();
            }
            GameInfo.JavaPath = Config.getConfig("JavaPath");
            Lang.Load(new File(GameInfo.Rundir + tpf + "MCXA.Lang" + tpf + Config.getConfig("Lang")));
            //到这。。。

            if (!new File(GameInfo.GameDir).exists()) {
                JOptionPane.showMessageDialog(null, Lang.getLang("Main_NoMinecraftDir"));
                File fi = new File(GameInfo.GameDir + GameInfo.tpf + "versions");
                fi.mkdirs();

// System.exit(0);
            }
            l.Log("Generating window...");
            java.awt.EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    new MCLaucherXA().setVisible(true);
                }

            });
        } catch (HeadlessException | IOException | ClassNotFoundException | IllegalAccessException | InstantiationException | UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel fbbq;
    private javax.swing.JButton jButton1;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JList jList1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JLabel lxbq;
    // End of variables declaration//GEN-END:variables
static String getTpf() {
        String a = System.getProperty("os.name");
        if (a.contains("Windows")) {
            return "\\";
        } else {
            return "/";
        }
    }

    void BrushLabels(int index) throws JSONException, IOException {
        JSONObject jo = new JSONObject(ReadFile(GameInfo.GameDir + tpf + "versions" + tpf + jList1.getSelectedValue().toString() + tpf + jList1.getSelectedValue().toString() + ".json"));

        lxbq.setText(jo.getString("type"));
        fbbq.setText(jo.getString("releaseTime"));
    }

    static String ReadFile(String path) throws FileNotFoundException, IOException {

        File file = new File(path);
        FileReader r = new FileReader(file);
        char c[] = new char[(int) file.length()];
        r.read(c);
        return String.valueOf(c);
    }

    static void GetAss() throws ParserConfigurationException {
        //  System.out.println("Getting Ass");
        String ver;

        // System.out.println("FUCK");
        ad.setVersion(GameInfo.assVersion);
        try {
            PrintStream ps = System.out;
            // DefaultListModel m = new DefaultListModel();
            boolean is1_6 = false;
            ver = new JSONObject(ReadFile(GameInfo.GameDir + tpf + "versions" + tpf + GameInfo.assVersion + tpf + GameInfo.assVersion + ".json")).getString("id");
            ps.println("= =");
            if (ver.contains("-")) {
                ver = ver.substring(0, ver.indexOf("-"));
            }
            try {
                //(HttpURLConnection)  (new URL("http://bmclapi.bangbang93.com/indexes/" + ver + ".json").openConnection()).;
                //  urlfile = new URL(remoteFilePath);
                HttpURLConnection httpUrl = (HttpURLConnection) new URL(DownLoadURL.getURL(DownLoadURL.INDEXES, Integer.valueOf(Config.getConfig("DownSou"))) + "/" + ver + ".json").openConnection();
                httpUrl.connect();
                BufferedInputStream bis = new BufferedInputStream(httpUrl.getInputStream());
            } catch (Exception e) {
                ver = "1.7.4";
                is1_6 = true;
            }
            if (true) {
                //以下为最新资源文件
                JSONObject jo = new JSONObject(downloadFile(DownLoadURL.getURL(DownLoadURL.INDEXES, Integer.valueOf(Config.getConfig("DownSou"))) + "/" + ver + ".json")).getJSONObject("objects");
                //   System.out.println(ver + jo);
                JSONArray ja = jo.names();
                ad.add(DownLoadURL.getURL(DownLoadURL.INDEXES, Integer.valueOf(Config.getConfig("DownSou"))) + "/" + ver + ".json", GameInfo.GameDir + tpf + "assets" + tpf + "indexes" + tpf + ver + ".json", null, false);
                for (int a = 0; a < ja.length(); a++) {
                    JSONObject jo2 = jo.getJSONObject(ja.getString(a));
                    String hash = jo2.getString("hash");
                    String path = hash.substring(0, 2) + tpf + hash;
                    File f = new File(GameInfo.GameDir + tpf + "assets" + tpf + "objects" + tpf + path);
                    if (f.exists()) {
                        continue;
                    }
                    if (!f.getParentFile().exists()) {
                        f.getParentFile().mkdirs();
                    }

                    ad.add(DownLoadURL.getURL(DownLoadURL.ASSETS, Integer.valueOf(Config.getConfig("DownSou"))) + "/" + path, GameInfo.GameDir + tpf + "assets" + tpf + "objects" + tpf + path, GameInfo.GameDir + tpf + "assets" + tpf + ja.get(a), true);
                }

                ad.start();
                ad.setVisible(true);
            }
            //ad.dispose();
        } catch (IOException | JSONException | HeadlessException e) {
            e.printStackTrace();
//System.out.println(e);
        }
    }

    public static String downloadFile(String remoteFilePath) throws IOException {

        URL urlfile = null;
        HttpURLConnection httpUrl = null;
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        File f = new File(GameInfo.Rundir + GameInfo.tpf + "temp.tmp");
        File xxxx = new File(f.getParent());
        //StringWriter sb=new StringWri();
        xxxx.mkdirs();

//      f.mkdirs();
        try {
            urlfile = new URL(remoteFilePath);
            httpUrl = (HttpURLConnection) urlfile.openConnection();
            httpUrl.connect();
            bis = new BufferedInputStream(httpUrl.getInputStream());
            bos = new BufferedOutputStream(new FileOutputStream(f));

            int len = 2048;
            byte[] b = new byte[len];
            while ((len = bis.read(b)) != -1) {
                bos.write(b, 0, len);
            }
            bos.flush();
            bis.close();
            httpUrl.disconnect();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                bis.close();
                bos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        String x = ReadFile(GameInfo.Rundir + GameInfo.tpf + "temp.tmp");
        f.deleteOnExit();
        return x;
    }

}

class checkUpdate implements Runnable {

    JLabel l;

    public checkUpdate(JLabel l) {

        this.l = l;
    }

    @Override
    public void run() {
        if (Updater.NeedUpdate()) {
            l.setVisible(true);
        }
        // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}
